//
//  ViewController.m
//  first app
//
//  Created by 小明 林 on 12-7-16.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "ViewController.h"

@implementation ViewController

@synthesize msglabel;

- ( int ) randomSibowl
{
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
    [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
    [dateFormatter setDateFormat:@"A"];
    
    double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
    
    srand( seed );
    int num = rand()%6 + 1;
    return num;
}

- (IBAction) clickDice
{
    int r1, r2, r3;
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r1 = rand()%6 + 1;
    }
    
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r2 = rand()%6 + 1;
    }
    
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r3 = rand()%6 + 1;
    }
    
    NSString * msg = [[NSString alloc] initWithFormat: @"r1:%d,r2:%d,r3:%d", r1, r2, r3 ];

    [msglabel setText: msg];
}

- (IBAction) clickCorn
{
    int r1, r2, r3;
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r1 = rand()%2;
    }
    
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r2 = rand()%2;
    }
    
    {
        NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
        [dateFormatter setDateStyle:NSDateFormatterMediumStyle];
        [dateFormatter setTimeStyle:NSDateFormatterShortStyle];
        [dateFormatter setDateFormat:@"A"];
        
        double seed = [[dateFormatter stringFromDate:[NSDate date]] doubleValue];
        
        srand( seed );
        r3 = rand()%2;
    }
    
    NSString * msg = [[NSString alloc] initWithFormat: @"r1:%d,r2:%d,r3:%d", r1, r2, r3 ];
    
    [msglabel setText: msg];
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
	[super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
	[super viewDidDisappear:animated];
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}

@end
